#include "controlador.h"

Controlador::Controlador(QObject *parent) :
    QObject(parent)
{

}
void Controlador::startClient(){

    const int Timeout = 5 * 1000000;

    QTcpSocket socket;
    //socket.connectToHost("10.13.13.4", 30000);
    socket.connectToHost("10.13.13.4",(qint16)30000);

    if (!socket.waitForConnected(Timeout)) {
            qDebug()<<"erro no socket";
            return;
    }

    while (socket.bytesAvailable() < (int)sizeof(quint16)) {
        if (!socket.waitForReadyRead(Timeout)) {
            qDebug()<<"erro no socket";
            return;
        }
    }

    quint16 blockSize;
    QDataStream in(&socket);
    in.setVersion(QDataStream::Qt_4_0);
    in >> blockSize;
    qDebug()<<"numero de bytes"<<blockSize;
    while (socket.bytesAvailable() < blockSize) {
        if (!socket.waitForReadyRead(Timeout)) {
            qDebug()<<"erro no socket";
             return;
        }
    }

    QString fortune;
    in >> fortune;
        qDebug()<<"recebeu "<<fortune;

}
